﻿using System.Collections.Generic;
using System.Web.Mvc;
using tophd2.Models.Entity;
using tophd2.Models.Service;

namespace tophd2.Controllers
{
    public class CategoryController : Controller
    {
        //
        // GET: /Category/

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult ImageByCategory(long? categoryId, int hotpage = 1, int newpage = 1)
        {
            ImageService iservice = new ImageService();
            List<Images> ilistHot = iservice.GetImages(0, 1, 4 * hotpage - 3, 4 * hotpage);
            List<Images> ilistNew = iservice.GetImages(0, 0, 4 * newpage - 3, 4 * newpage);
            int totalRecord = 0;
            List<Images> totalImage = iservice.GetImages(0, 0, 0, 0);
            totalRecord = totalImage.Count;
            List<Images> iList = null;
            List<Images> iList2 = null;
            if (categoryId != null)
            {
                iList = iservice.GetImages(categoryId, 1, 4 * hotpage - 3, 4 * hotpage);
                iList2 = iservice.GetImages(categoryId, 0, 4 * newpage - 3, 4 * newpage);
                List<Images> totalImage2 = iservice.GetImages(categoryId, 0, 0, 0);
                totalRecord = totalImage2.Count;
            }
            CategoryService cs = new CategoryService();
            List<HotItem> lhot = cs.GetHotItem(1);
            ViewData["hotImage"] = lhot;
            ViewData["iListHot"] = ilistHot;
            ViewData["iListNew"] = ilistNew;
            ViewData["iList"] = iList;
            ViewData["iList2"] = iList2;
            ViewBag.totalRecord = totalRecord;
            ViewBag.cateId = categoryId;
            ViewBag.hotpage = hotpage;
            ViewBag.newpage = newpage;
            return View();
        }
        [HttpGet]
        public ActionResult VideoByCategory(long? categoryId, int hotpage = 1, int newpage = 1)
        {
            VideoService vservice = new VideoService();
            List<Video> vlistHot = vservice.GetVideo(0, 1, 20 * hotpage - 19, 20 * hotpage); //1: download
            List<Video> vlistNew = vservice.GetVideo(0, 0, 20 * newpage - 19, 20 * newpage); //0: moi nhat
            int totalRecord = 0;
            List<Video> totalVideo = vservice.GetVideo(0, 0, 0, 0);
            totalRecord = totalVideo.Count;
            //List<Video> vList = null;
            //List<Video> vList2 = null;
            //if (categoryId != null)
            //{
            //    vList = vservice.GetVideo(categoryId, 1, 4 * hotpage - 3, 4 * hotpage);
            //    vList2 = vservice.GetVideo(categoryId, 0, 4 * newpage - 3, 4 * newpage);
            //    List<Video> totalVideo2 = vservice.GetVideo(categoryId, 0, 0, 0);
            //    totalRecord = totalVideo2.Count;
            //}
            CategoryService cs = new CategoryService();
            Category cate = cs.GetCategoryById(categoryId);
            List<HotItem> lhot = cs.GetHotItem(9);
            ViewData["category"] = cate;
            ViewData["hotVideo"] = lhot;
            ViewData["vListHot"] = vlistHot;
            ViewData["vListNew"] = vlistNew;
            //ViewData["vList"] = vList;
            //ViewData["vList2"] = vList2;
            ViewBag.totalRecord = totalRecord;
            ViewBag.cateId = categoryId;
            ViewBag.hotpage = hotpage;
            ViewBag.newpage = newpage;
            return View();
        }
        [HttpGet]
        public ActionResult NewsByCategory(long? categoryId, int hotpage = 1, int newpage = 1)
        {
            NewsService nservice = new NewsService();
            List<News> nlistHot = nservice.GetNews(0, 1, 4 * hotpage - 3, 4 * hotpage); //1: download
            List<News> nlistNew = nservice.GetNews(0, 0, 4 * newpage - 3, 4 * newpage); //0: moi nhat
            int totalRecord = 0;
            List<News> totalNews = nservice.GetNews(0, 0, 0, 0);
            totalRecord = totalNews.Count;
            //List<News> nList = nservice.GetNews(categoryId,0,1,10);
            List<News> nList = null;
            List<News> nList2 = null;
            if (categoryId != null)
            {
                nList = nservice.GetNews(categoryId, 1, 4 * hotpage - 3, 4 * hotpage);
                nList2 = nservice.GetNews(categoryId, 0, 4 * newpage - 3, 4 * newpage);
                List<News> totalNews2 = nservice.GetNews(categoryId, 0, 0, 0);
                totalRecord = totalNews2.Count;
            }
            CategoryService cs = new CategoryService();
            List<HotItem> lhot = cs.GetHotItem(3);
            ViewData["hotNews"] = lhot;
            ViewData["nListHot"] = nlistHot;
            ViewData["nListNew"] = nlistNew;
            ViewData["nList"] = nList;
            ViewData["nList2"] = nList2;
            ViewBag.totalRecord = totalRecord;
            ViewBag.cateId = categoryId;
            ViewBag.hotpage = hotpage;
            ViewBag.newpage = newpage;
            //ViewData["nList"] = nList;
            return View();
        }
    }
}
